#include <iostream>
#include <vector>
#include "geometry.h"

int main()
{
   int n, m;
   std :: cout.precision(100);
   std :: cin >> n;
   std :: vector<Point> s(n);
       
   for (int i = 0; i < n; i++)
   {
      std :: cin >> s[i];
   }
   std :: cin >> m;

   for (int i = 0; i < m; i++) 
   {
      Point p;
      std:: cin >> p;
      Point res = closest_point(s, p);
      std:: cout << std::fixed << res.x << " " << res.y << "\n";
   }
   return 0;
}